package com.ShottingWord.shared;

import java.util.Map;
import java.util.Random;

import com.google.common.collect.HashBiMap;
import com.google.common.collect.BiMap;

/**
 * 
 * Store the relationship between word and picture.
 * @author nini
 *
 */

public class WordMap {	
	private BiMap<String, String> wordHashMap;
	
	public WordMap(){
		this.wordHashMap = HashBiMap.create();
	}
	
	public WordMap(Map<String, String> wordMap){
		this.wordHashMap = HashBiMap.create(wordMap);
	}
	
	/**
	 * void for accessing list of values in map
	 */
	public String[] getPicIdList()	{
		String[] result=(String[]) wordHashMap.values().toArray();
		return result;
	}
	
	/**
	 * void for accessing list of keys in map
	 */
	public String[] getWordList()	{
		String[] result=(String[]) wordHashMap.keySet().toArray();
		return result;
	}
	
	
	/**
	 * 
	 * @param wordMap
	 */
	public void setWordHashMap(Map<String, String> wordMap){
		wordHashMap.clear();
		wordHashMap.putAll(wordMap);
	}
	
	/**
	 * 
	 * @return
	 */
	public BiMap<String, String> getWordHashMap(){
		return wordHashMap;
	}
	
	/**
	 * 
	 * @param words
	 * @return The picture ID of given words
	 */
	public String getPicId(String words){
		return wordHashMap.get(words);
	}
	
	/**
	 * 
	 * @param picId
	 * @return The words of given picture ID
	 */
	public String getWord(String picId){
		return wordHashMap.inverse().get(picId);
	}
	
	/**
	 * Put a word and picture ID to the map.
	 * @param words
	 * @param picId
	 */
	public void put(String words, String picId){
		wordHashMap.put(words, picId);
	}
	
	/**
	 * put all entries in wordMap into WordMap
	 * @param wordMap
	 */
	public void putAll(Map<String, String> wordMap){
		wordHashMap.putAll(wordMap);
	}
}
